package ui.importandsaleman;

import javax.swing.JFrame;

import tool.MyButton;
import tool.MyLabel;
import ui.client.ClientManagementPanel;
import vo.UserVo;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;



public class ImportandsaleFrame extends JFrame{
	private static final long serialVersionUID = 7575628597837757876L;



	
	private UserVo user;
	private JPanel panel;
	
	public ImportandsaleFrame(UserVo user){

		this.setContentPane(new JPanel() {

			private static final long serialVersionUID = -8067534092982934270L;

			@Override
			public void paint(Graphics g) {
				this.setBackground(new Color(0, 0, 0, 0));
				Image background = Toolkit.getDefaultToolkit().getImage(
						"Graphics/framebackground.jpg");
				g.drawImage(background, 0, 0, null);
				super.paint(g);
			}
		});
		this.user=user;
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.addWindowListener(new WindowListener() {
			
			@Override
			public void windowOpened(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowIconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowDeiconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowDeactivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowClosed(WindowEvent e) {
				System.exit(0);
			}
			
			@Override
			public void windowActivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
		});
		this.setSize(850,536);
		this.setResizable(false);
		getContentPane().setLayout(null);
		this.setVisible(true);
		
		
		

        JButton button = new MyButton("Graphics/Button119-23.png");
        button.setText("主界面");
		button.setBounds(10, 27, 119, 23);
		button.addActionListener(e->ImportandsalemanWelcomeManagement());
		getContentPane().add(button);
		
		JLabel label = new MyLabel("客户信息管理");
		label.setBounds(35, 108, 83, 15);
		getContentPane().add(label);
		
		JButton button_1 = new MyButton("Graphics/Button119-23.png");
		button_1.setText("客户管理");
		button_1.setBounds(10, 134, 119, 23);
		button_1.addActionListener(e->ClientManagement());
		getContentPane().add(button_1);
		
		JLabel label_1 = new MyLabel("制定单据");
		label_1.setBounds(49, 212, 54, 15);
		getContentPane().add(label_1);
		
		JButton btnNewButton = new MyButton("Graphics/Button119-23.png");
		btnNewButton.setText("进货单");
		btnNewButton.setBounds(10, 237, 119, 23);
		btnNewButton.addActionListener(e->JHDManagement());
		getContentPane().add(btnNewButton);
		
		JButton button_2 =new MyButton("Graphics/Button119-23.png");
		button_2.setText("进货退货单");
		button_2.setBounds(10, 272, 119, 23);
		button_2.addActionListener(e->JHTHDManagement());
		getContentPane().add(button_2);
		
		JButton button_3 = new MyButton("Graphics/Button119-23.png");
		button_3.setText("销售单");
		button_3.setBounds(10, 307, 119, 23);
		button_3.addActionListener(e->XSDManagement());
		getContentPane().add(button_3);
		
		JButton button_4 = new MyButton("Graphics/Button119-23.png");
		button_4.setText("销售退货单");
		button_4.setBounds(10, 342, 119, 23);
		button_4.addActionListener(e->XSTHDManagement());
		getContentPane().add(button_4);
		
		this.setVisible(true);
		this.user=user;
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setResizable(false);
		
		this.ImportandsalemanWelcomeManagement();

		
	}



	private void XSTHDManagement() {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new SaleAndReturnDocumentPanel(user, null, true, o.销售单据类型.销售退货单,false,false);
		panel.setBounds(160,40,746,433);
		getContentPane().add(panel);		
	}

	private void XSDManagement() {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new SaleAndReturnDocumentPanel(user, null, true, o.销售单据类型.销售单,false,false);
		panel.setBounds(160,40,746,433);
		getContentPane().add(panel);
	}

	private void JHTHDManagement() {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new ImportAndReturnDocumentPanel(user, null, true,o.进货单据类型.进货退货单,false,false);
		panel.setBounds(160,40,746,433);
		getContentPane().add(panel);
	}

	private void JHDManagement() {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new ImportAndReturnDocumentPanel(user, null,true,o.进货单据类型.进货单,false,false);
		panel.setBounds(160,40,746,433);
		getContentPane().add(panel);
	}

	private void ClientManagement() {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new ClientManagementPanel(user);
		panel.setBounds(160,40,746,433);
		getContentPane().add(panel);
	}
	
	private void ImportandsalemanWelcomeManagement() {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel=new ImportandsalemanWelcomePanel();
		panel.setBounds(160,40,646,433);
		getContentPane().add(panel);
	}
	


	
}
